package service

import "errors"

type IMusic interface {
	ID() string

	Title() string
	Url() (string, error)
	Artist() string
	Uploader() string
	CoverUrl() string
}

type IPlaylist interface {
	ID() string

	Title() string
	Musics() []IMusic
	checkMusicExist(music IMusic) (bool, error)
	addMusic(music IMusic) error
	removeMusic(music IMusic) error
}

func MusicBuilder(uuid string) IMusic {
	return &DebugMusic{
		uuid: uuid,
	}
}

func PlaylistBuilder(uuid string) IPlaylist {
	return &DebugPlaylist{
		uuid: uuid,
	}
}

var (
	Err_MusicAlreadyInPlaylist = errors.New("music already in playlist")
	Err_MusicNotInPlaylist     = errors.New("music not in playlist")
)

func AddMusicToPlaylist(music IMusic, playlist IPlaylist) error {
	var alreadyIn bool
	var err error
	if alreadyIn, err = playlist.checkMusicExist(music); err != nil {
		return err
	}
	if alreadyIn {
		return Err_MusicAlreadyInPlaylist
	}
	return playlist.addMusic(music)
}

func RemoveMusicFromPlaylist(music IMusic, playlist IPlaylist) error {
	var alreadyIn bool
	var err error
	if alreadyIn, err = playlist.checkMusicExist(music); err != nil {
		return err
	}
	if !alreadyIn {
		return Err_MusicNotInPlaylist
	}
	return playlist.removeMusic(music)
}
